<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html" xmlns:required="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <title>layui</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" href="/lib/layui-v2.5.4/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all"/>
    <link rel="stylesheet" href="/css/public.css" media="all"/>
    <style>
        .layui-table-click {
            background-color: #99BBFF !important;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layuimini-search">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">医保类型</label>
                            <div class="layui-input-inline">
                                <select name="yblx" id="yblx" required="required">
                                    <option value="12103" selected="selected">十堰医保</option>
                                    <option value="42038101004">丹江医保</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">住院号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="patientId" autocomplete="off" class="layui-input"></input>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input dateSelect" name="startDate" id="startDate"
                                       placeholder="yyyy-MM-dd"></input>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input dateSelect" name="endDate" id="endDate"
                                       placeholder="yyyy-MM-dd"></input>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <a class="layui-btn layui-btn-normal" lay-submit="" lay-filter="data-search-btn"><i
                                    class="layui-icon layui-icon-search"></i>查询</a>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>

<script src="/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'layer', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layer = layui.layer,
            laydate = layui.laydate,
            iconPickerFa = layui.iconPickerFa;

        var myDate = new Date();
        myDate.setDate(myDate.getDate() - 7);
        laydate.render({
            elem: '#startDate'
            , theme: '#393D49',
            calendar: true,
            min: '2019-09-27',
            value: myDate
        });


        laydate.render({
            elem: '#endDate'
            , theme: '#393D49',
            calendar: true,
            min: '2019-09-27',
            value: new Date()
        });

        $(function () {
            $.ajax({
                url: "/sys/findSysMenuCombox",
                method: "post",
                success: function (data) {
                    if (data.code == '0') {
                        var str = $("#parentId").html();
                        $.each(data.data, function (key, val) {
                            str += '<option value="' + key + '">' + val + '</option>';
                        })
                        $("#parentId").html(str);
                        form.render('select');
                    } else {
                        console.info(data.msg);
                        layer.alert(data.msg);
                    }
                }
            });
        });

        table.render({
            elem: '#currentTableId',
            url: '/hwn/findMipsSettleMentUploadDetail',
            method: 'post',
            cols: [ [
                {type: "checkbox", fixed: "left"},
                {field: 'id', title: 'ID', width: 80, sort: true, hide: true},
                {field: 'pro2', title: '统筹区', width: 80,},
                {field: 'patientId', title: '住院号', width: 110, sort: true},
                {field: 'name', title: '姓名', width: 80},
                {field: 'visitId', title: '次数', width: 60},
                {field: 'outMajorDiagCode', title: '出院诊断编码', width: 120},
                {field: 'outMajorDiagName', title: '出院诊断名称', width: 120},
                {
                    field: 'settlementDate',
                    title: '结算时间',
                    sort: true,
                    width: 160,
                    templet: '<div>{{ layui.util.toDateString(d.settlementDate, "yyyy-MM-dd HH:mm:ss") }}</div>'
                },
                {field: 'zfy', title: '总费用', width: 100},
                {field: 'tczf', title: '统筹支付', width: 90},
                {field: 'grzf', title: '个人自费', width: 90},
                {field: 'grzf1', title: '个人自付', width: 90},
                {field: 'dbyb', title: '大病医保', width: 90},
                {field: 'skje', title: '刷卡金额', width: 90},
                {field: 'xjzf', title: '现金支付', width: 90},
                {field: 'bcbx', title: '补充保险', width: 90},
                {field: 'ybfd', title: '医保负担', width: 90},
                {field: 'mzjz', title: '民政救助', width: 90},
                {field: 'yycd', title: '医院承担', width: 90},
                {field: 'patiVisitIdInsurance', title: '医保就诊流水号', minWidth: 120, hide: true},
                {field: 'settlementId', title: '结算主记录ID', minWidth: 100, hide: true},
                {field: 'settlementUploadId', title: '单病种上传记录ID', minWidth: 120, hide: true},
                //{title: '操作', minWidth: 140, templet: '#currentTableBar', fixed: "right", align: "center"},
                {
                    title: '操作', minWidth: 140, templet: function (d) {
                        if (d.settlementUploadId == "" || d.settlementUploadId == undefined) {
                            return '<a class="layui-btn layui-btn-xs layui-btn-normal data-count-edit" lay-event="edit"><i class="layui-icon layui-icon-upload-circle"></i>上报</a>';
                        } else {
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon layui-icon-close"></i>撤销上报</a>';
                        }
                    }, fixed: "right", align: "center"
                }

            ]],
            size: 'sm',
            skin: 'line',
            height: 'full-160',
            // toolbar: true, //开启头部工具栏，并为其绑定左侧模板,
            // defaultToolbar: ['filter', 'exports', 'print'],
            limits: [20, 50, 100, 200],
            limit: 20,
            even: true,
            page: true,
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                //console.log(res);

                //得到当前页码
                //console.log(curr);

                //得到数据总量
                //console.log(count);
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {

            if (obj.checked == true) {
                if (obj.type == "all") {
                    $('.layui-table-body table.layui-table tbody tr').addClass('layui-table-click');
                }
                if (obj.type == "one") {
                    //点击单行
                    if (obj.checked == true) {
                        obj.tr.addClass('layui-table-click');
                    } else {
                        obj.tr.removeClass('layui-table-click');
                    }
                }
            } else {
                if (obj.type == "all") {
                    //点击全不选
                    $('.layui-table-body table.layui-table tbody tr').removeClass('layui-table-click');
                }
                if (obj.type == "one") {
                    //点击全选之后点击单行
                    if (obj.tr.hasClass('layui-table-click')) {
                        obj.tr.removeClass('layui-table-click');
                    }
                }
            }
        });


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // var result = JSON.stringify(data.field);
            // console.info (data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    yblx: data.field.yblx,
                    patientId: data.field.patientId,
                    startDate: data.field.startDate,
                    endDate: data.field.endDate
                }
            }, 'data');

            return false;
        });

        // 监听刷新操作
        $(".data-refresh-btn").on("click", function () {
            table.reload('currentTableId', {
                where: {} //设定异步数据接口的额外参数
                //,height: 300
            });
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var index = layer.msg('调用医保接口中...', {
                icon: 16
                , shade: 0.08,
                time: 0
            });
            if (obj.event === 'edit') {

                var jysr = data.outMajorDiagCode + "|" + data.outMajorDiagName + "|" + data.patiVisitIdInsurance + "|" + "1" + "|99999";
                var tcq = "";
                if (data.pro2 == "十堰") {
                    tcq = "12103";
                } else if (data.pro2 == "丹江") {
                    tcq = "42038101004";
                }
                var result;
                try {
                    result = JSON.parse(window.parent.SychiCall('3130', tcq, jysr));
                    layer.close(index);
                    if (result.resultSet[0].Code != '1') {
                        layer.alert("医保返回交易失败," + result.resultSet[0].jyscMsg);
                    } else {
                        index = layer.msg('医保交易成功,正在保存结果...', {
                            icon: 16
                            , shade: 0.08,
                            time: 0
                        });
                        $.ajax({
                            url: "/hwn/saveMipsSettleMentUploadDetail",
                            method: "post",
                            success: function (data) {
                                layer.close(index);
                                if (data.code == '0') {
                                    layer.msg('上报成功...', {time: 3000, icon: 6});
                                    table.reload('currentTableId', {
                                        where: {}
                                    });
                                } else {
                                    console.error(data.msg);
                                    layer.alert(data.msg);
                                }
                            },
                            data: {
                                settlementInfoId: data.settlementInfoId,
                                operator: "99999",
                                cancelFlag: '0'
                            }
                        });
                    }
                } catch (e) {
                    layer.alert("调用医保交易失败,请检查检查浏览器版本是否正确,是否安装医保环境," + e.toLocaleString());
                }
            } else if (obj.event === 'delete') {
                layer.confirm('确定撤销上报 ' + data.name + ' 么？', {
                    title: "提示",
                    icon: 3,
                    skin: 'layer-ext-moon'
                }, function (index) {

                    var jysr = data.outMajorDiagCode + "|" + data.outMajorDiagName + "|" + data.patiVisitIdInsurance + "|" + "2" + "|99999";
                    var tcq = "";
                    if (data.pro2 == "十堰") {
                        tcq = "12103";
                    } else if (data.pro2 == "丹江") {
                        tcq = "42038101004";
                    }
                    var result;
                    try {
                        result = JSON.parse(window.parent.SychiCall('3130', tcq, jysr));
                        layer.close(index);
                        console.info(result);
                        console.info(result.resultSet[0].code);
                        if (result.resultSet[0].Code != '1') {
                            layer.alert("医保返回交易失败," + result.resultSet[0].jyscMsg);
                        } else {
                            index = layer.msg('医保交易成功,正在保存结果...', {
                                icon: 16
                                , shade: 0.08,
                                time: 0
                            });
                            $.ajax({
                                url: "/hwn/saveMipsSettleMentUploadDetail",
                                method: "post",
                                success: function (data) {
                                    layer.close(index);
                                    if (data.code == '0') {
                                        layer.msg('撤销成功...', {time: 3000, icon: 6});
                                        table.reload('currentTableId', {
                                            where: {}
                                        });
                                    } else {
                                        console.info(data.msg);
                                        layer.alert(data.msg);
                                    }
                                },
                                data: {
                                    id: data.settlementUploadId,
                                    settlementInfoId: data.settlementInfoId,
                                    operator: "99999",
                                    cancelFlag: '0'
                                }
                            });
                        }
                    } catch (e) {
                        layer.alert("调用医保交易失败,请检查检查浏览器版本是否正确,是否安装医保环境," + e.toLocaleString());
                    }

                    $.ajax({
                        url: "/sys/deleteSysMenu",
                        method: "post",
                        data: {id: data.id, cancelFlag: "1"},
                        success: function (data) {
                            if (data.code == '0') {
                                layer.closeAll('page');
                                table.reload('currentTableId');
                                form.render('select');
                                layer.msg('删除成功...', {time: 3000, icon: 6});
                            } else {
                                console.info(data.msg);
                                layer.alert(data.msg);
                            }
                        },
                        error: function (xhr, msg) {
                            layer.alert(xhr.code + " " + msg);
                        }
                    });
                });
            }
        });
    });
</script>

</body>
</html>
